<!--调试经营管理-市场机会列表页-->
<template>
  <PageTemplate>
    <div class="sys-process" slot="content">
      <el-form
        inline
        :model="query"
        ref="query"
        label-position="right"
        label-width="82px"
        class="search-collapse-pro-form"
      >
        <SearchCollapsePro :isAdvSearch="false">
          <div slot="title" class="search-collapse-pro-title">
            <el-form-item label-width="0px">
              <el-input v-model="query.marketName" placeholder="市场机会名称/客户名称">
                <el-button slot="append" icon="el-icon-search" @click="queryDataTableLike"></el-button>
              </el-input>
            </el-form-item>
          </div>
        </SearchCollapsePro>
      </el-form>
      <el-row class="row-empty-20"></el-row>
      <PageTableCollapse :collapseStatus="true">
        <el-row slot="title">
          <el-col>
            <div>
              <el-button v-if="showBtn" type="primary" icon="el-icon-download" @click="exportHandle">
                 导出
              </el-button>
            </div>
          </el-col>
        </el-row>
        <el-table
          class="table"
          border
          ref="multipleTable"
          :data="tables"
          tooltip-effect="dark"
          style="width: 100%"
          :show-overflow-tooltip="true"
          @selection-change="handleSelectionChange"
          :header-cell-style="{background:tableHeaderBGC}"
        >
          <!-- <el-table-column align="center" type="selection" width="60"></el-table-column> -->
          <el-table-column type="index" :index="indexMethod" :label="$t('cm.no')" align="center" width="60" fixed></el-table-column>
          <el-table-column prop="marketName" label="项目名称" align="center" width="200"></el-table-column>
          <!-- <el-table-column prop="marketName" label="项目名称" align="center" width="200"></el-table-column> -->
          <el-table-column prop="projectType" label="项目类型" align="center" width="200"></el-table-column>
          <el-table-column prop="customerName" label="客户名称" align="center" width="200"></el-table-column>
          <el-table-column prop="customerType" label="客户类型" align="center" width="200"></el-table-column>
          <el-table-column prop="estimateAmount" label="预计合同金额（万元）" align="center" width="200"></el-table-column>
          <el-table-column prop="projectArea" label="项目区域" align="center" width="200"></el-table-column>
          <el-table-column prop="projectDept" label="项目所属部门" align="center" width="200"></el-table-column>
          <el-table-column prop="projectContract" label="业务类别" align="center" width="200"></el-table-column>
          <!-- <el-table-column prop="projectArea" label="项目区域" align="center" width="200"></el-table-column>
          <el-table-column prop="projectAddress" label="项目厂址" align="center" width="200"></el-table-column>
          <el-table-column prop="sourceFunds" label="资金来源" align="center" width="200"></el-table-column>
          <el-table-column prop="projectContract" label="项目承揽模式" align="center" width="200"></el-table-column> -->
          <el-table-column :label="$t('cm.operate')" prop="statussss" align="center" width="100" fixed="right">
            <template slot-scope="scope">
              <ListBtn :options="btns" :row-data="scope.row" @triggerListBtn="handleListBtn" :show-btn="showBtn"></ListBtn>
            </template>
          </el-table-column>
        </el-table>
        <div class="block pager-customer">
          <el-pagination
            background
            layout="total,prev,pager, next,jumper"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
          </el-pagination>
        </div>
      </PageTableCollapse>
    </div>
  </PageTemplate>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import PageTemplate from '@/components/common/PageTemplate'
import PageTableCollapse from '@/components/common/PageTableCollapse'
import SearchCollapsePro from '@/components/common/SearchCollapsePro'
import ListBtn from '@/components/btn/ListBtn'
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import {COMMON} from '@/utils/commonUtil'
import Pagination from '@/mixins/Pagination'
import HasBtn from '@/mixins/HasBtn'
import opr_management from '@/api/opr_management'
import {dateFtt} from '@/utils/datetime'

export default {
  components: { 
    PageTemplate, 
    PageTableCollapse, 
    SearchCollapsePro, 
    ListBtn 
  },
  data () {
    return {
      query: {
        marketName: "",
      },
      tables:[],
      btns: [
      {
        value: 'look',
        label: 'cm.look'
      },
      {
        value: 'edit',
        label: 'cm.edit'
      }
    ]

    }
  },
  created () {
    this.getAllDataTable()
  },
  mixins: [Pagination, HasBtn],
  computed: {
    ...mapState({
      tableHeaderBGC: state => state.common.tableHeaderBGC
    })
  },
  methods:{
    handleListBtn({btn,row}){
      if(btn==="look"){//查看
        COMMON.routerTo(Constant.ROUTE_RUN_MARKET_LOOK.index, this.$router, { id: row.id })
      }else{//编辑
        COMMON.routerTo(Constant.ROUTE_RUN_MARKET_EDIT.index, this.$router, { id: row.id })
      }
    },
    // 导出
    exportHandle () {
       let params = Object.assign({},this.query,{
        pageNum:this.pagingCurrentPageNum,
        pageSize:this.pagingPageSize
      })
      let fileName = `调试经营管理_市场机会_${dateFtt('yyyy-MM-dd', new Date())}`
      opr_management.marketListExportExcel(params, response => {
        if (response.code === Constant.RT_SUCCESS) {
          COMMON.downloadLinkByUrl(response.data.webRequestUrl, fileName)
        } else {
          ALERT.alertResp(response)
        }
      })
    },
    queryDataTableLike () {
      this.getAllDataTable();
    },
     getAllDataTable () {
      this.queryTableList({
        ...this.query,
        pageNum: this.pagingCurrentPageNum,
        pageSize: this.pagingPageSize
      })
    },
    //统一与后台操作的方法
    queryTableList (params) {
      //这里的params是对象
      //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
      let _this = this
      let tables = []
      let totalCount = 0
      opr_management.getMarketList(params, result => {
        if (result.code === Constant.RT_SUCCESS) {
          //表格数据  数组            
          tables = result.data.results
          //分页数据
          totalCount = result.data.totalRows
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.data.msg)
        }
        _this.setPagingTotal(totalCount)
        this.tables = tables
      })
    },
  }
}
  
</script>

<style lang="scss">
  
</style>